package servlet;

import DBTool.DB;
import bean.Attence;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/stu")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sql="select * from attence a,student s where a.sid=s.sid order by aid";
        ResultSet rs = DB.query(sql);
        ArrayList<Attence> list = new ArrayList<>();
        try {
            while (rs.next()){
                int aid = rs.getInt("aid");
                String time = rs.getString("time");
                int type = rs.getInt("type");
                int sid = rs.getInt("sid");
                String sname=rs.getString("sname");
                Attence attence = new Attence(aid, time, type, sid, sname);
                list.add(attence);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        request.setAttribute("list",list);
        request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
